angular.module('loginApp',[])
    .controller('loginCtrl',['$scope','$window','$http',function($scope,$window,$http){
        $scope.user={username:'admin',password:'123456'};

        $scope.dashboard = 'login';
        $scope.changeDashboard = function(x){
            $scope.dashboard=x;
        };

        $scope.login = function () {

            var postCfg = {
                headers: {'Content-Type': 'application/json'}
            };
            // $http.post('http://localhost:9999/login',$scope.user,postCfg).then(function (res) {
           $http.post('http://test.mbsway.com:9999/login',$scope.user,postCfg).then(function (res) {
               var response = res.data;
               if ( response.status == 1 ){
                   $window.localStorage['userId'] = JSON.parse(response.result.authorities[0].authority).id ;
                   $window.localStorage['accessToken'] = response.result.token;
                   window.location.href = config.home_page;
               }else{
                   swal("Login Failed!", "check your account or password.", "error");
               }
            });
        }

    }]);